package com.qf.service.impl;

import com.qf.dao.AdminDao;
import com.qf.entity.Admin;
import com.qf.exception.CustomerException;
import com.qf.service.AdminService;
import com.qf.utils.RedisUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author zdl
 * @date 2025/3/6
 */
@Service
public class AdminServiceImpl implements AdminService {
    @Resource
    private RedisUtil redisUtil;
    @Resource
    private AdminDao adminDao;
    @Override
    public String  login(String username, String password) {
        Admin admin = adminDao.selectByUsername(username);
        if (admin == null) {
            throw new CustomerException("3001","账号不存在");
        }
        if (!admin.getPassword().equals(password)) {
            throw new CustomerException("3002","密码错误");
        }
        String token = UUID.randomUUID().toString();
        // 缓存token
        redisUtil.setCacheObject(token,admin,60*3, TimeUnit.SECONDS);
        return token;
    }
}



